package com.frank.service.test3;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @Author: huweifeng
 * @Date: 2024/12/11
 * @Description: 测试Buffer集中写
 **/
public class TestGatheringWrites {
    public static void main(String[] args) {
        try (FileChannel channel = new RandomAccessFile("writes.txt", "rw").getChannel()){
            ByteBuffer word1buffer = StandardCharsets.UTF_8.encode("hello");
            ByteBuffer word2buffer = StandardCharsets.UTF_8.encode("word");
            ByteBuffer word3buffer = StandardCharsets.UTF_8.encode("你好");
            channel.write(new ByteBuffer[]{word1buffer, word2buffer, word3buffer});

        } catch (IOException e) {

        }
    }
}
